import requests
import os

# 定义照片的URL地址
photo_url = "http://n.sinaimg.cn/news/crawl/117/w550h367/20220417/a3a9-08b2ca6dffe4210149dda424adf0734f.jpg"

# 定义保存照片的桌面路径（Windows）
desktop_path = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')

# 定义照片的文件名
photo_filename = "downloaded_photo.jpg"

# 构建完整的文件路径
photo_path = os.path.join(desktop_path, photo_filename)

# 发送GET请求获取照片内容
response = requests.get(photo_url, stream=True)

# 检查请求是否成功
if response.status_code == 200:
    # 打开文件并写入照片内容
    with open(photo_path, 'wb') as f:
        for chunk in response.iter_content(1024):
            f.write(chunk)
    print(f"照片已成功保存到桌面，路径为：{photo_path}")
else:
    print(f"下载照片失败，状态码为：{response.status_code}")